package com.pro.service.imple;

import com.pro.mapper.JsDeptMapper;
import com.pro.pojo.JsClosure;
import com.pro.pojo.JsDept;
import com.pro.pojo.JsUnseal;
import com.pro.pojo.JsUser;
import com.pro.service.JsDeptService;
import com.pro.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:JsDeptServiceImple
 * Package:com.pro.service.imple
 * Description: 后台部门ServiceImple
 *
 * @Date:2022/1/19 下午 9:03
 * @Author: WYH
 */
@Service
public class JsDeptServiceImple implements JsDeptService {

    @Autowired(required = false)
    private JsDeptMapper jsDeptMapper;

    @Autowired
    private RedisCache redisCache;

    /**
     * @Author WYH
     * @Description //TODO 查看部门名称
     * @Date 下午 9:04 2022/1/19
     * @Param
     * @return List<JsDept>
     **/
    @Override
    public List<JsDept> getJsDeptName() {
        List<JsDept> AlldeptList = redisCache.getCacheList("dept");
        if (!AlldeptList.isEmpty()){
            return AlldeptList;
        }
        JsDept js = new JsDept();
        js.setId(0);
        js.setParentId(-1);
        js.setDeptName("所有部门");
        List<JsDept> Alldept = jsDeptMapper.getJsDeptName();
        Alldept.add(js);
        redisCache.setCacheList("dept",Alldept);
        return Alldept;
    }

    /**
     * @Author WYH
     * @Description //TODO 查询后台用户信息
     * @Date 下午 9:18 2022/1/19
     * @Param account,trueName.deptName,registerDate,limit,page
     * @return  List<JsUser>
     **/
    @Override
    public List<JsUser> getJsUser(String account, String trueName, String deptName, String registerDate, Integer limit, Integer page) {
        page = (page -1 ) * limit;
        List<JsUser> jsUser = jsDeptMapper.getJsUser(account, trueName, deptName, registerDate, limit, page);
        return jsUser;
    }

    /**
     * @Author WYH
     * @Description //TODO 计算后台用户信息
     * @Date 下午 9:18 2022/1/19
     * @Param account,trueName.deptName,registerDate
     * @return  Integer
     **/
    @Override
    public Integer countJsUser(String account, String trueName, String deptName, String registerDate) {
        Integer integer = jsDeptMapper.countJsUser(account, trueName, deptName, registerDate);
        return integer;
    }

    /**
     * @Author WYH
     * @Description //TODO 更新账号状态
     * @Date 下午 7:20 2022/1/20
     * @Param jsUser
     * @return  false | true
     **/
    public Boolean updateStatus(JsUser jsUser){
        Boolean updateStatus = jsDeptMapper.updateStatus(jsUser);
        return updateStatus;
    }
    /**
     * @Author WYH
     * @Description //TODO 将解封后的账号添加到解封日志中
     * @Date 下午 2:55 2022/2/9
     * @Param userId,type,unsealDate
     * @return false | true
     **/
    public Boolean insertUnseal(Integer userId,Integer type,String unsealDate){
        Boolean aBoolean = jsDeptMapper.insertUnseal(userId, type, unsealDate);
        return aBoolean;
    };
    /**
     * @Author WYH
     * @Description //TODO 解封后封停日志封停结束时间改为当前的时间
     * @Date 下午 3:01 2022/2/9
     * @Param id,userId,endDate
     * @return false | true
     **/
    public Boolean updateUserEndDate(Integer id,Integer userId,String endDate){
        Boolean aBoolean = jsDeptMapper.updateUserEndDate(id, userId, endDate);
        return aBoolean;
    };

    /**
     * @Author WYH
     * @Description //TODO 查询用户详情
     * @Date 下午 7:33 2022/1/20
     * @Param userId
     * @return  JsUser
     **/
    public JsUser getJsUserById(Integer userId){
        JsUser jsUserById = jsDeptMapper.getJsUserById(userId);
        return jsUserById;
    }

    /**
     * @Author WYH
     * @Description //TODO 高级检索
     * @Date 下午 8:37 2022/1/21
     * @Param email,phone,idCard,status,sex,enabled,limit,page
     * @return  List<JsUser>
     **/
    public List<JsUser> getSearchJsUser(String email,String phone,String idCard,String status,String sex,String enabled,Integer limit,Integer page){
        page = (page - 1 ) * limit;
        List<JsUser> searchJsUser = jsDeptMapper.getSearchJsUser(email, phone, idCard, status, sex, enabled, limit, page);
        return searchJsUser;
    }

    /**
     * @Author WYH
     * @Description //TODO 计算高级检索的个数
     * @Date 下午 8:37 2022/1/21
     * @Param  email,phone,idCard,status,sex,enabled
     * @return integer
     **/
    public Integer countSearchJsUser(String email,String phone,String idCard, String status,String sex,String enabled){
        Integer integer = jsDeptMapper.countSearchJsUser(email, phone, idCard, status, sex, enabled);
        return integer;
    }

    /**
     * @Author WYH
     * @Description //TODO 权限
     * @Date 下午 8:59 2022/1/21
     * @Param userId
     * @return  List<JsUser>
     **/
    public List<JsUser> getUserSettings(Integer userId){
        List<JsUser> userSettings = jsDeptMapper.getUserSettings(userId);
        return userSettings;
    }

    /**
     * @Author WYH
     * @Description //TODO 删除后台权限
     * @Date 下午 8:51 2022/1/24
     * @Param userId
     * @return  true | false
     **/
    public Boolean delUserStatus(Integer userId){
        Boolean delUserStatus = jsDeptMapper.delUserStatus(userId);
        return delUserStatus;
    }

    /**
     * @Author WYH
     * @Description //TODO 对后台用户账户进行编辑
     * @Date 下午 9:36 2022/1/24
     * @Param jsUser
     * @return JsDept
     **/
    public Boolean updateUser(JsUser jsUser){
        Boolean updateUser = jsDeptMapper.updateUser(jsUser);
        return updateUser;
    }

    /**
     * @Author WYH
     * @Description //TODO 封停
     * @Date 下午 6:11 2022/1/25
     * @Param jsClosure
     * @return  true | false
     **/
    public Boolean addUserClosure(JsClosure jsClosure){
        Boolean addUserClosure = jsDeptMapper.addUserClosure(jsClosure);
        return addUserClosure;
    }

    /**
     * @Author WYH
     * @Description //TODO 更改后台用户账号状态
     * @Date 下午 6:16 2022/1/25
     * @Param userId,status,enabled
     * @return  true | false
     **/
    public Boolean updateUserStatus(Integer userId,Integer status,Integer enabled){
        Boolean updateUserStatus = jsDeptMapper.updateUserStatus(userId, status, enabled);
        return updateUserStatus;
    }

    /**
     * @Author WYH
     * @Description //TODO 添加后台人员
     * @Date 下午 8:51 2022/1/27
     * @Param jsUser
     * @return  true | false
     **/
    public Boolean addBackgroundUser(JsUser jsUser){
        Boolean addUser = jsDeptMapper.addBackgroundUser(jsUser);
        return addUser;
    }
    /**
     * @Author WYH
     * @Description //TODO 添加后台权限
     * @Date 下午 8:51 2022/1/24
     * @Param jsUser
     * @return  true | false
     **/
    public Boolean addUserStatus(List<JsUser> jsUser){
        Boolean addUserStatus = jsDeptMapper.addUserStatus(jsUser);
        return false;
    }

    /**
     * @Author WYH
     * @Description //TODO 后台人员解封日志
     * @Date 下午 9:07 2022/2/7
     * @Param account,deptName,unsealDate,limit,page
     * @return  List<JsUnseal>
     **/
    public List<JsUnseal> getPeopleUnsealing(String account, String deptName, String unsealDate, Integer limit, Integer page){
        page = (page-1)*limit;
        List<JsUnseal> peopleUnsealing = jsDeptMapper.getPeopleUnsealing(account, deptName, unsealDate, limit, page);
        return peopleUnsealing;
    }

    /**
     * @Author WYH
     * @Description //TODO 计算后台人员解封日志个数
     * @Date 下午 9:13 2022/2/7
     * @Param account,deptName,unsealDate
     * @return  Integer
     **/
    public Integer countGetPeopleUnsealing(String account, String deptName, String unsealDate){
        Integer integer = jsDeptMapper.countGetPeopleUnsealing(account, deptName, unsealDate);
        return integer;
    }

}
